package com.lanou.tipsy.fragment.guide;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.lanou.tipsy.R;

/**
 *    引导页 轮播图配置
 */
public class GuidePageFragment extends Fragment {
	private static final String KEY_CONTENT = "GuidePageFragment:Position";
	protected static final int[] CONTENT = new int[] {
			//绑定4张引导页
			R.drawable.landing_page1,
			R.drawable.landing_page2,
			R.drawable.landing_page3,
			R.drawable.landing_page4
	};
	private int mPosition;

	public static GuidePageFragment newInstance(int position) {
		GuidePageFragment fragment = new GuidePageFragment();
		fragment.mPosition = position;
		return fragment;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		if ((savedInstanceState != null)
				&& savedInstanceState.containsKey(KEY_CONTENT)) {
			mPosition = savedInstanceState.getInt(KEY_CONTENT);
		}
		View root = inflater
				.inflate(R.layout.welcome_viewpage, container, false);
		root.setBackgroundResource(CONTENT[mPosition]);
		return root;
	}

	@Override
	//保存当前的状态
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		outState.putInt(KEY_CONTENT, mPosition);
	}
}
